/**
  ******************************************************************************
  * @file    Project/main.c 
  * @author  MCD Application Team
  * @brief   Main program body
  ******************************************************************************
  *
  ******************************************************************************
  */ 


/* Includes ------------------------------------------------------------------*/
#include "system_gd32f1x0.h"
#include "gd32f1x0_conf.h"
#include "osObjects.h"                      // RTOS object definitions
#include "systimer.h"
#include "mbapp.h"
#include "peripheral.h"
#include "at24xx.h"

/*
#include "taskmanger.h"
#include "taskapp.h"
#include "systask.h"
#include "system.h"
#include "motor.h"
#include "key.h"
#include "display.h"
*/
/* Private defines -----------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/

/* Private functions ---------------------------------------------------------*/
void PortInit(void);

/*****************************************************************************//*!
* @brief   	main .
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
int main()
{
	PortInit();
	
    SystemCoreClockUpdate();

    osKernelInitialize ();                    // initialize CMSIS-RTOS

    // initialize peripherals here
    //AdcInsertedInit();
	AdcRegularInit();
	I2cMasterInit();
    // create 'thread' functions that start executing,
    Init_Thread ();
    // example: tid_name = osThreadCreate (osThread(name), NULL);

    osKernelStart ();                         // start thread execution 
    
    osThreadYield ();                         // suspend thread
    //for(;;){};
}

/*****************************************************************************//*!
* @brief   	port init.
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void PortInit()
{
	RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOARST, ENABLE);
	RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOBRST, ENABLE);
	RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOCRST, ENABLE);
	
	//pin mode ,input with B00
	GPIOA->PUPD =  GPIO_PUPD_PUPD2_0 | GPIO_PUPD_PUPD3_0;                    //pull up
	//GPIOA->CTLR =  GPIO_CTLR_CTLR2_1 | GPIO_CTLR_CTLR3_1;                  //specific function
	
	//pin mode ,input with B00
	GPIOB->CTLR =   GPIO_CTLR_CTLR8_0 |                                      //output
					GPIO_CTLR_CTLR9_0 |                                      //output
					GPIO_CTLR_CTLR10_0;                                      //output
	//output mode
	GPIOB->OMODE = 0;
	//output speed
	GPIOB->OSPD =   GPIO_OSPD_OSPD8_0 | GPIO_OSPD_OSPD8_1 |                  //50MHz
					GPIO_OSPD_OSPD9_0 | GPIO_OSPD_OSPD9_1 |                  //50MHz
					GPIO_OSPD_OSPD10_0 | GPIO_OSPD_OSPD10_1 ;                //50MHz
	//poll up / poll down cfg
	GPIOB->PUPD = 0;
	
	GPIOB->BOR  = GPIO_BOR_BOR8;
	
}

/*****************************************************************************//*!
* @brief   	system tick hook.
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void SysTickHook()
{
	SysTickCnt++;
}
